<%@page import="com.situ.web.vo.PageInfo"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.situ.web.entity.Course"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<%@ include file="header.jsp"%>
	<meta charset="UTF-8">
	<title>Insert title here</title>
	
</head>
<body>
	<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
	
	<script type="text/html" id="topToolbar">
  		<div class="layui-btn-container">
    		<button class="layui-btn layui-btn-sm" lay-event="deleteAll">批量删除</button>
    		<button class="layui-btn layui-btn-sm" lay-event="insert">添加</button>
  		</div>
	</script>
	
	<script type="text/html" id="rightToolbar">
  		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
	
	<script type="text/javascript">
		layui.use('table', function(){
		  var table = layui.table;
		  
		  table.render({
		    elem: '#tableId'
		    ,url:'${path}/course?method=selectLayuiByPage'
		    ,toolbar: '#topToolbar' //开启头部工具栏
		    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
		    ,cols: [[
		       {type: 'checkbox', fixed: 'left'}
		      ,{field:'id', title: 'ID', sort: true}
		      ,{field:'name', title: '用户名'}
		      ,{field:'credit', title: '学分', sort: true}
		      ,{fixed: 'right', title:'操作', toolbar: '#rightToolbar', width:150}
		    ]]
		  	,page: true
		  	,id: 'tableReload'
		  });
		  
		  //头工具栏事件
		  table.on('toolbar(tableFilter)', function(obj){
		    var checkStatus = table.checkStatus(obj.config.id);
		    switch(obj.event){
		      case 'deleteAll':
		    	  
		      break;
		      case 'insert':
		    	  layer.open({
		    		  type : 2,
		    		  title : '添加',
		    		  area : ['350px', '200px'],
		    		  content : '${path}/course?method=getCourseInsertPage'
		    	  });
		      break;
		      
		      //自定义头工具栏右侧图标 - 提示
		      case 'LAYTABLE_TIPS':
		        layer.alert('这是工具栏右侧自定义的一个图标按钮');
		      break;
		    };
		  });
		  
		  //监听行工具右侧toolbar事件
		  table.on('tool(tableFilter)', function(obj){
		    var data = obj.data;// data: {credit: 4, id: 14, name: "UI3333"}
		    console.log(obj)
		    if(obj.event === 'del'){
		    	layer.confirm(
					'您确定要删除么？',
					{icon : 3},
					function(index){//点击确认触发
						$.post(
							'${path}/course?method=delete',
							{'id' : data.id},
							function(jsonResult) {
								// {code: 0, msg : "删除成功"}
								console.log(jsonResult);
								if (jsonResult.code == 0) {
									// mylayer.okUrl(jsonObj.msg, '${path}/course?method=selectLayuiByPage');
									mylayer.okMsg(jsonResult.msg);
									table.reload('tableReload');
								} else {
									mylayer.errorMsg(jsonResult.msg);
								}
							},
							'json'
						);
						layer.close(index);
					}
				);
		    } else if(obj.event === 'edit'){
		      
		    }
		  });
		  
		  
		});
		
	</script>
</body>
</html>